package com.example.compose

import androidx.compose.animation.animateColor
import androidx.compose.animation.core.animateDp
import androidx.compose.animation.core.tween
import androidx.compose.animation.core.updateTransition
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.size
import androidx.compose.material3.Button
import androidx.compose.material3.Text
import androidx.compose.runtime.*
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp

@Preview
@Composable
fun SharedTransformExample() {
    var isSelected by remember { mutableStateOf(false) }

    val transition = updateTransition(targetState = isSelected, label = "Transition")

    val color by transition.animateColor(
        transitionSpec = { tween(durationMillis = 1000) },
        label = "Color Transition"
    ) { selected ->
        if (selected) Color.Blue else Color.Red
    }

    val size by transition.animateDp(
        transitionSpec = { tween(durationMillis = 1000) },
        label = "Size Transition"
    ) { selected ->
        if (selected) 200.dp else 100.dp
    }

    Box(
        modifier = Modifier
            .size(size)
            .background(color)
    )

    Button(onClick = { isSelected = !isSelected }) {
        if (isSelected) {
            Text(text = "Deselect")
        } else {
            Text(text = "Select")
        }
    }
}
